#ifndef _DETECTOR_H_
#define _DETECTOR_H_
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "config.h"
#include <queue>

#define PI 3.14159265
#define BIG 0
#define SMALL 1

using namespace std;
using namespace cv;

typedef struct ANGLE
{
	float yaw;
	float pitch;
} Angle;

class Armor
{
private:
	vector<Point2f> rect;

public:
	int number;
	Point2f center;
	float d_x, d_z, d_y;

private:
	void getPnp();

public:
	Armor();
	Armor(vector<Point2f> rect_target, Rect roi_rect, int num);
	Armor(const Armor& other);
};

class Detector
{
private:
	Mat binary;	 //binary image
	Mat outline; //outline image
	int num;
	Rect Armor_roi;
	vector<vector<Point>> contours;
	float matchrank[1500][1500];
	Ptr<ml::SVM> svm = ml::SVM::load("cxy_svm_5_1.xml");

public:
	Mat src; //source image
	Mat src_out;
	bool islost; //1代表丢失
	Mat number_roi;
	int color_thresh = 20; //通道相减二值化阈值
	int gray_thresh = 20;  //灰度图二值化阈值
	vector<Armor> detect_armor;
	Armor target_armor;

private:
	Mat pointProcess(Mat srcImg, int enemyColor, int color_threshold, int gry_threshold);
	void imgProcess(Mat &tempBinary);
	/////////////////////////////装甲板//////////////////////////////////
	int getNumber(vector<Point2f> rect_t);
	int isArmorPattern(Mat &front);
	void getRoi(Point2f center, Point2f size);

public:
	Detector();
	Detector(Mat src0);
	void getResult(bool color);
	void getSrcImage(Mat src0);
	void getBinaryImage(int color);
	void getContours();
	void getTarget();
};
#endif
